//
//  Rock.m
//  MessangerSkeleton
//
//  Created by User-16 on 4/25/14.
//  Copyright (c) 2014 IOTrainingCamp. All rights reserved.
//

#import "Rock.h"
#import "cocos2d.h"
#import "Configuration.h"

@interface Rock ()

@property GameObjectType* type;
@end

@implementation Rock

- (instancetype)init
{
    self = [super initWithSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"stone01.gif"]];
    if (self) {
        
        self.type = kObstacleLow;
        self.scale = 0.25;

        
        //TODO: should be loaded from a plist and this should be separate method common for all sprites
        int num = 4;
        CGPoint* rock = malloc(sizeof(CGPoint)*num);
        rock[0] = ccp(183.2f, -137.4f);
        rock[1] = ccp(128.1f, 175.6f);
        rock[2] = ccp(-120.8f, 142.0f);
        rock[3] = ccp(-178.4f, -163.2f);

        
        //CGPoint offset = ccp(self.contentSize.width*self.scale, self.contentSize.height*self.scale);
        CGPoint offset = ccp(178.4f, 178.2f);
        
        for(int i=0; i< num; i++)
        {
            rock[i] = ccp(rock[i].x + offset.x, rock[i].y + offset.y);
        }
        
        

        self.physicsBody = [CCPhysicsBody bodyWithPolygonFromPoints:rock count:num cornerRadius:20];
        
        free(rock);
        self.scale = 0.20;
        self.physicsBody.sensor = YES;
        self.physicsBody.collisionType = @"obstacle";
    }
    return self;
}

-(void)update:(CCTime)delta
{
    if(self.position.x + self.boundingBox.size.width < 0)
        [self removeFromParentAndCleanup:YES];
}
@end
